package com.woniu.user.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.woniu.user.domain.Customer;
import com.woniu.user.domain.User;
import com.woniu.user.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 管理员用户信息Controller
 * 
 * @author yy
 * @date 2023-04-03
 */
@RestController
@RequestMapping("/user/tbuser")
@Api("管理员用户信息管理")
public class UserController extends BaseController
{
    @Autowired
    private IUserService userService;

    /**
     * 查询管理员用户信息列表
     */
    //@PreAuthorize("@ss.hasPermi('apartment:tbuser:list')")
    @GetMapping("/list")
    @ApiOperation("管理员用户信息分页查询")
    public TableDataInfo list(User user)
    {
        startPage();
        List<User> list = userService.selectUserList(user);
        return getDataTable(list);
    }

    /**
     * 导出管理员用户信息列表
     */
    //@PreAuthorize("@ss.hasPermi('apartment:tbuser:export')")
    @Log(title = "管理员用户信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("管理员用户信息导出")
    public void export(HttpServletResponse response, User user)
    {
        List<User> list = userService.selectUserList(user);
        ExcelUtil<User> util = new ExcelUtil<User>(User.class);
        util.exportExcel(response, list, "管理员用户信息数据");
    }

    /**
     * 获取管理员用户信息详细信息
     */
    //@PreAuthorize("@ss.hasPermi('apartment:tbuser:query')")
    @GetMapping(value = "/{userId}")
    @ApiOperation("根据主键查询管理员用户信息")
    @ApiImplicitParam(name = "userIds", value = "用户ID", required = true, dataType = "Long")
    public AjaxResult getInfo(@PathVariable("userId") Long userId)
    {
        return success(userService.selectUserByUserId(userId));
    }

    /**
     * 新增管理员用户信息
     */
    //@PreAuthorize("@ss.hasPermi('apartment:tbuser:add')")
    @Log(title = "管理员用户信息", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("添加管理员用户信息")
    public AjaxResult add(@RequestBody User user)
    {
        return toAjax(userService.insertUser(user));
    }

    /**
     * 修改管理员用户信息
     */
    //@PreAuthorize("@ss.hasPermi('apartment:tbuser:edit')")
    @Log(title = "管理员用户信息", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("更新管理员用户信息")
    public AjaxResult edit(@RequestBody User user)
    {
        return toAjax(userService.updateUser(user));
    }

    /**
     * 删除管理员用户信息
     */
    //@PreAuthorize("@ss.hasPermi('apartment:tbuser:remove')")
    @Log(title = "管理员用户信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{userIds}")
    @ApiOperation("删除管理员用户信息")
    @ApiImplicitParam(name = "userIds", value = "主键数组", required = true, dataType = "Long")
    public AjaxResult remove(@PathVariable Long[] userIds)
    {
        return toAjax(userService.deleteUserByUserIds(userIds));
    }

    @RequestMapping("/login")
    public User login(@RequestParam("username") String username, @RequestParam("password") String password){

        User user =  userService.login(username,password);
        return user;
    }
}
